$(function () {
    // i18n.init();
    var data = {
        "student": [{
                "name": "张三",
                "age": 18,
                "sex": "男",
                "title": "title",
            },
            {
                "name": '张四',
                "sex": "男",
                "age": 22
            },
            {
                "name": "李四",
                "sex": "男",
                "age": 18,
                "title": 'title',
            }
        ]

    };
    var myTemplate = Handlebars.compile($("#table-template").html());
    //将json对象用刚刚注册的Handlebars模版封装，得到最终的html，插入到基础table中。
    $('#tableList').html(myTemplate(data));
    var defaults = 'zh-CN';
    i18n.init({
        fallbackLng: 'zh-CN', //初始化语言
        debug: true,
        useLocalStorage: true,
        returnObjectTrees: true,
        ns: {
            namespaces: ['translation'],
            defaultNs: 'tran'
        },

        resStore: {
            'zh-CN': {
                'tran': {
                    "title": "中国",
                    "table": {
                        "name": "姓名",
                        "sex": "性别",
                        "age": "年龄"
                    }
                }
            },
            'en': {
                'tran': {
                    "title": "中国",
                    "table": {
                        "name": "name",
                        "sex": "sex",
                        "age": "age"
                    }
                }
            }
        }
    }, function (e) {
        console.log($.t('title'))
        $('[data-i18n]').i18n();
    });

    defaults = i18n.lng(); //获取当前cookie中设置的语言

    var selected = $("#language");
    selected.find('option[value=' + defaults + ']').prop('selected', true);

    selected.on('change', function (event) {
        var $this = $(event.currentTarget)
        var lng = $this.find('option:selected').val();

        i18n.setLng(lng, function () {
            $('[data-i18n]').i18n();
            console.log(i18n.t('title'))
        });
    });



});
